package com.hangwei.paperless.adapter.sub;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.SubSetInfo;
import com.hangwei.paperless.view.SealHelper;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/12/1.
 */

public class SubSetAdapter extends MyAdapter<SubSetInfo, BaseViewHolder> {
    public SubSetAdapter(@Nullable List<SubSetInfo> data) {
        super(R.layout.item_sub_set, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SubSetInfo item) {
        if (item.isComplete) {
            helper.setBackgroundColor(R.id.llItemView, mContext.getResources().getColor(R.color.complete));
        } else
            helper.setBackgroundColor(R.id.llItemView, mContext.getResources().getColor(R.color.white));
        helper.addOnClickListener(R.id.llItemView);
        helper.setText(R.id.tvSeq, Tools.checkedString(item.location))
                .setText(R.id.tvQty, Tools.checkedString(item.qty))
                .setText(R.id.tvMin, TextUtils.isEmpty(Tools.checkedString(item.inlMin))?"--":Tools.checkedString(item.inlMin))
                .setText(R.id.tvMax, TextUtils.isEmpty(Tools.checkedString(item.inlMax))?"--":Tools.checkedString(item.inlMax))
                .setText(R.id.tvActual, TextUtils.isEmpty(Tools.checkedString(item.inlActual))?"--":Tools.checkedString(item.inlActual))
                .setText(R.id.tvOutActual,  TextUtils.isEmpty(Tools.checkedString(item.outerActual))?"--":Tools.checkedString(item.outerActual))
                .setText(R.id.tvInnerActual, TextUtils.isEmpty(Tools.checkedString(item.inlActual))?"--":Tools.checkedString(item.inlActual))
                .setText(R.id.tvRemark, Tools.checkedString(item.remark));
        if (TextUtils.isEmpty(Tools.checkedString(item.outerMin)) && !TextUtils.isEmpty(Tools.checkedString(item.outerMax))) {
            helper.setText(R.id.tvOutFace, Tools.checkedString(item.outerMax) + "Max");
        } else if (!TextUtils.isEmpty(Tools.checkedString(item.outerMin)) && TextUtils.isEmpty(Tools.checkedString(item.outerMax))) {
            helper.setText(R.id.tvOutFace, Tools.checkedString(item.outerMin) + "Min");
        } else if (!TextUtils.isEmpty(Tools.checkedString(item.outerMin)) && !TextUtils.isEmpty(Tools.checkedString(item.outerMax)))
            helper.setText(R.id.tvOutFace, Tools.checkedString(item.outerMin) + "-" + Tools.checkedString(item.outerMax));
        else
            helper.setText(R.id.tvOutFace, "--");
        if (TextUtils.isEmpty(item.innerMin) && !TextUtils.isEmpty(item.innerMax)) {
            helper.setText(R.id.tvInnerFace, Tools.checkedString(item.innerMax) + "Max");
        } else if (!TextUtils.isEmpty(item.innerMin) && TextUtils.isEmpty(item.innerMax)) {
            helper.setText(R.id.tvInnerFace, Tools.checkedString(item.innerMin) + "Min");
        } else if (!TextUtils.isEmpty(item.innerMin) && !TextUtils.isEmpty(item.innerMax))
            helper.setText(R.id.tvInnerFace, Tools.checkedString(item.innerMin) + "-" + Tools.checkedString(item.innerMax));
        else
            helper.setText(R.id.tvInnerFace, "--");
        RelativeLayout flUserSeal = helper.getView(R.id.flUserSeal);
        SealHelper sealHelper = new SealHelper(mContext) {
            @Override
            protected void onSeal() {

            }
        };
        sealHelper.bindData(new SealHelper.SealBean(true, item.technicianStampId, item.technicianId, item.technicianStampTypeCode, item.technicianStampCode, item.technicianDate, item.technician, false));
        flUserSeal.removeAllViews();
        flUserSeal.addView(sealHelper.getItemView());
        if (item.isComplete) {
            helper.setBackgroundColor(R.id.flUserSeal, mContext.getResources().getColor(R.color.complete));
        } else
            helper.setBackgroundColor(R.id.flUserSeal, mContext.getResources().getColor(R.color.white));
    }
}
